package chapter7;

/**
 * @author yuh
 * @date 2018/5/3 14:45
 * @description
 */
public class DongtaizGuihua {

    static int[] arr;

    static int breakNum(int n) {
        if (n == 1) {
            return 1;
        }
        if (arr[n] != -1) {
            return arr[n];
        }
        int res = -1;
        for (int i = 1; i <= n - 1; i++) {
            res = max3(res, i * (n - i), i * breakNum(n - i));
            arr[i] = res;
        }

        return res;
    }

    static int b2(int n) {
        if (n == 1) {
            return 1;
        }
        arr[1] = 1;
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= i - 1; j++) {
                arr[i] = max3(arr[i], j * (i - j), j * arr[i - j]);
            }
        }
        return arr[n];
    }


    private static int max3(int a, int b, int c) {
        return Math.max(a, Math.max(b, c));
    }

    public static void main(String[] args) {
        int a = 3;
        arr = new int[a + 1];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = -1;
        }
        System.out.println(b2(a));
    }
}
